<?php

class Ebx_Error {

	protected static $_errorLevel = 0;

	protected static $_handleUnknownError = false;

	static function setErrorLevel($level) {
		self::$_errorLevel = $level;
	}

	static function handleUnknownError($flag = true) {
		self::$_handleUnknownError = (bool)$flag;
	}

	static function defaultErrorHandler($errno, $errstr, $errfile, $errline) {
		if (self::$_errorLevel < $errno) {
			return true;
		}
		switch ($errno) {
			case E_USER_ERROR:
				echo "<b>User level error</b> [$errno] $errstr<br />\n";
				echo "file: <b>$errfile</b><br />\n";
				echo "line: <b>$errline</b><br />\n";
				echo "<br />\n";
				exit(1);
				break;

			case E_USER_WARNING:
				echo "<b>User level warning</b> [$errno] $errstr<br />\n";
				echo "file: <b>$errfile</b><br />\n";
				echo "line: <b>$errline</b><br />\n";
				echo "<br />\n";
				break;

			case E_USER_NOTICE:
				echo "<b>User level notice</b> [$errno] $errstr<br />\n";
				echo "file: <b>$errfile</b><br />\n";
				echo "line: <b>$errline</b><br />\n";
				echo "<br />\n";
				break;

			default:
				if (self::$_handleUnknownError) {
					echo "Unknown error type: [$errno] $errstr<br />\n";
					echo "file: <b>$errfile</b><br />\n";
					echo "line: <b>$errline</b><br />\n";
					break;
				}
		}
		return true;
	}

}

?>